//
//  HomePageTopView.m
//  DBAChain
//
//  Created by Evan on 2018/9/5.
//  Copyright © 2018 Evan. All rights reserved.
//

#import "HomePageTopView.h"
#import <Masonry.h>
#import "CommonData.h"

#define splid   30

@implementation HomePageTopView{
    UITextField *txtNotice;
    CGFloat diffY;
}

-(instancetype)init{
    self = [super init];
    if (self) {
        [self initUI];
    }
    return self;
}


-(void)initUI{
    self.backgroundColor = [UIColor colorWithRed:25/255.0 green:30/255.0 blue:46/255.0 alpha:1];
    
    [self btnNotice];
    [self labelStatus];
    [self imgChainWa];
    [self labelGET];
    [self labelSL];
    [self labelInviteFriend];
    [self btnInviteFriend];
    [self viewBottom];
    [self viewTitle];
    [self btnIntroduce];
    [self imgChainD];
}

///通知文本
-(UIButton*)btnNotice{
    if (!_btnNotice) {
        _btnNotice = [[UIButton alloc]init];
        [self addSubview:_btnNotice];
        [_btnNotice mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self).offset(20);
            make.right.mas_equalTo(self).offset(-20);
            make.top.offset(30);
            make.height.offset(40);
        }];
        [_btnNotice setTitle:@"10月9日前参加最新邀请活动可获得20GTE奖励" forState:UIControlStateNormal];
        _btnNotice.titleLabel.font = [UIFont systemFontOfSize:13];
        _btnNotice.backgroundColor = [UIColor colorWithRed:255/255 green:255/255 blue:255/255 alpha:0.03];
        _btnNotice.layer.masksToBounds = YES;
        _btnNotice.layer.cornerRadius = 20;
        _btnNotice.titleLabel.textAlignment = NSTextAlignmentCenter;
        [_btnNotice setTintColor:[UIColor whiteColor]];
    }
    return _btnNotice;
}

//挖矿状态
-(UILabel*)labelStatus{
    if (!_labelStatus) {
        _labelStatus = [[UILabel alloc]init];
        [self addSubview:_labelStatus];
        [_labelStatus mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self).offset(20);
            make.right.mas_equalTo(self).offset(-20);
            make.top.mas_equalTo(self.btnNotice.mas_bottom).offset(40);
            make.height.offset(20);
        }];
        _labelStatus.text = @"等待开启...";
        _labelStatus.textAlignment = NSTextAlignmentCenter;
        _labelStatus.font = [UIFont systemFontOfSize:12];
        _labelStatus.textColor = [UIColor whiteColor];
    }
    return _labelStatus;
}


///挖矿图片
- (UIImageView*)imgChainWa{
    if (!_imgChainWa) {
        _imgChainWa = [[UIImageView alloc]init];
        [self addSubview:_imgChainWa];
        [_imgChainWa mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(self);
            make.top.mas_equalTo(self.labelStatus.mas_bottom).offset(19);
            make.height.offset(265);
            make.width.offset(320);
        }];
        _imgChainWa.image = [UIImage imageNamed:@"chainWa"];
    }
    return _imgChainWa;
}

-(UIImageView*)imgChainD{
    if (!_imgChainD) {
        _imgChainD = [[UIImageView alloc]init];
        [self addSubview:_imgChainD];
        [_imgChainD mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(self);
            make.bottom.mas_equalTo(self.imgChainWa.mas_top).offset(30);
            make.height.offset(50);
            make.width.offset(35);
        }];
        _imgChainD.image = [UIImage imageNamed:@"chainD"];
        [self imgDbottom];
    }
    return _imgChainD;
}

-(void)imgDbottom{
    diffY = self.imgChainWa.frame.origin.y + 10;
    if (self.imgChainD.frame.origin.y != diffY) {
         self.imgChainD.frame = CGRectMake(self.imgChainD.frame.origin.x, diffY, self.imgChainD.frame.size.width, self.imgChainD.frame.size.height);
    }
    [UIView animateWithDuration:2 animations:^{
        self.imgChainD.frame = CGRectMake(self.imgChainD.frame.origin.x, self.imgChainD.frame.origin.y - splid, self.imgChainD.frame.size.width, self.imgChainD.frame.size.height);
    } completion:^(BOOL finished) {
        if (finished) {
            [self imgDTop];
        }
    }];
}

-(void)imgDTop{
    [UIView animateWithDuration:2 animations:^{
        self.imgChainD.frame = CGRectMake(self.imgChainD.frame.origin.x, self.imgChainD.frame.origin.y + splid, self.imgChainD.frame.size.width, self.imgChainD.frame.size.height);
    } completion:^(BOOL finished) {
        if (finished) {
            [self imgDbottom];
        }
    }];
}

//GET 余额
-(UILabel*)labelGET{
    if (!_labelGET) {
        
        //头img
        UIImageView *img = [[UIImageView alloc]init];
        [self addSubview:img];
        [img mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self).offset(20);
            make.top.mas_equalTo(self.imgChainWa.mas_bottom).offset(-39);
            make.width.offset(15);
            make.height.offset(15);
        }];
        img.image = [UIImage imageNamed:@"zsDBA"];
        
        //GET余额
        _labelGET = [[UILabel alloc]init];
        [self addSubview:_labelGET];
        [_labelGET mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self).offset(40);
            make.right.mas_equalTo(self).offset(-20);
            make.top.mas_equalTo(self.imgChainWa.mas_bottom).offset(-40);
            make.height.offset(20);
        }];
        _labelGET.text = @"GET 218.16000000";
        _labelGET.font = [UIFont systemFontOfSize:12];
        _labelGET.textColor = [UIColor whiteColor];
    }
    return _labelGET;
}


//GET 算力
-(UILabel*)labelSL{
    if (!_labelSL) {
        //头img
        UIImageView *img = [[UIImageView alloc]init];
        [self addSubview:img];
        [img mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self).offset(20);
            make.top.mas_equalTo(self.imgChainWa.mas_bottom).offset(-15);
            make.width.offset(15);
            make.height.offset(15);
        }];
        img.image = [UIImage imageNamed:@"slDBA"];
        
        //GET算力
        _labelSL = [[UILabel alloc]init];
        [self addSubview:_labelSL];
        [_labelSL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self).offset(40);
            make.right.mas_equalTo(self).offset(-20);
            make.top.mas_equalTo(self.labelGET.mas_bottom).offset(3);
            make.height.offset(20);
        }];
        _labelSL.text = @"算力 210";
        _labelSL.font = [UIFont systemFontOfSize:12];
        _labelSL.textColor = [UIColor whiteColor];
    }
    return _labelSL;
}

//邀请好友
-(UILabel*)labelInviteFriend{
    if (!_labelInviteFriend) {
        _labelInviteFriend = [[UILabel alloc]init];
        [self addSubview:_labelInviteFriend];
        [_labelInviteFriend mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self).offset(40);
            make.right.mas_equalTo(self).offset(-20);
            make.top.mas_equalTo(self.labelGET.mas_bottom).offset(3);
            make.height.offset(20);
        }];
        _labelInviteFriend.text = @"邀请朋友";
        _labelInviteFriend.textAlignment = NSTextAlignmentRight;
        _labelInviteFriend.font = [UIFont systemFontOfSize:12];
        _labelInviteFriend.textColor = [UIColor whiteColor];
    }
    return _labelInviteFriend;
}

//邀请好友
-(UIButton*)btnInviteFriend{
    if (!_btnInviteFriend) {
        _btnInviteFriend = [[UIButton alloc]init];
        [self addSubview:_btnInviteFriend];
        [_btnInviteFriend mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.mas_equalTo(self.labelInviteFriend.mas_top).offset(-5);
            make.right.mas_equalTo(self).offset(-25);
            make.height.offset(40);
            make.width.offset(40);
        }];
        [_btnInviteFriend setBackgroundImage:[UIImage imageNamed:@"好友"] forState:UIControlStateNormal];
        _btnInviteFriend.titleLabel.font = [UIFont systemFontOfSize:12];
        _btnInviteFriend.titleLabel.textColor = [UIColor whiteColor];
    }
    return _btnInviteFriend;
}

-(UIView*)viewBottom{
    if (!_viewBottom) {
        UIView *view = [[UIView alloc]init];
        [self addSubview:view];
        [view mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.mas_equalTo(self.mas_bottom).offset(0);
            make.right.mas_equalTo(self).offset(0);
            make.left.mas_equalTo(self).offset(0);
            make.height.offset(60);
        }];
        view.backgroundColor = LCFromRGB(248, 248, 248);
        
        _viewBottom = [[UIView alloc]init];
        [self addSubview:_viewBottom];
        [_viewBottom mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.mas_equalTo(self.mas_bottom).offset(10);
            make.right.mas_equalTo(self).offset(-20);
            make.left.mas_equalTo(self).offset(20);
            make.height.offset(100);
        }];
        _viewBottom.layer.cornerRadius = 10;
        _viewBottom.backgroundColor = [UIColor whiteColor];
        
        _viewBottom.layer.shadowColor = [UIColor blackColor].CGColor;
//        阴影的透明度
        _viewBottom.layer.shadowOpacity = 0.3f;
//        阴影的圆角
        _viewBottom.layer.shadowRadius = 4.0f;
        
    }
    return _viewBottom;
}

-(void)viewTitle{
    UILabel *labelTitle = [[UILabel alloc]init];
    [self.viewBottom addSubview:labelTitle];
    [labelTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self);
        make.width.offset(200);
        make.top.mas_equalTo(self.viewBottom).offset(10);
    }];
    labelTitle.text = @"GTE 智能算码";
    labelTitle.font = [UIFont fontWithName:@"PingFang-SC-Regular" size:15.8];
    labelTitle.textColor = [UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1];
    labelTitle.textAlignment = NSTextAlignmentCenter;
    
    UIImageView *img = [[UIImageView alloc]init];
    [self.viewBottom addSubview:img];
    [img mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self);
        make.top.mas_equalTo(labelTitle.mas_bottom).offset(5);
        make.width.offset(100);
        make.height.offset(2);
    }];
    img.image = [UIImage imageNamed:@"矩形Line"];
    img.backgroundColor = LCFromRGB(255, 84, 100);
    
    UILabel *labelDes = [[UILabel alloc]init];
    [self.viewBottom addSubview:labelDes];
    [labelDes mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.viewBottom).offset(20);
        make.width.offset(200);
        make.height.offset(15);
        make.top.mas_equalTo(img.mas_bottom).offset(20);
    }];
    labelDes.text = @"智能算码开启智能算力 new era";
    labelDes.font = [UIFont fontWithName:@"PingFang-SC-Regular" size:12.8];
    labelDes.textColor = LCFromRGB(136, 136, 136);
}

///介绍  按钮
- (UIButton*)btnIntroduce{
    if (!_btnIntroduce) {
        _btnIntroduce = [[UIButton alloc]init];
        [self addSubview:_btnIntroduce];
        [_btnIntroduce mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.mas_equalTo(self.viewBottom.mas_bottom).offset(-22);
            make.right.mas_equalTo(self.viewBottom.mas_right).offset(-20);
            make.height.offset(20);
            make.width.offset(50);
        }];
//        _btnIntroduce.backgroundColor = LCFromRGB(239, 130, 183);
        _btnIntroduce.titleLabel.font = [UIFont systemFontOfSize:12];
        _btnIntroduce.titleLabel.textColor = [UIColor whiteColor];
        [_btnIntroduce setTitle:@"介绍" forState:UIControlStateNormal];
        [_btnIntroduce setBackgroundImage:[UIImage imageNamed:@"homeJS"] forState:UIControlStateNormal];
//        _btnIntroduce.layer.cornerRadius = 15;
    }
    return _btnIntroduce;
}


@end
